package com.yin.myproject.netty.chapter06;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;

/**
 * @author Eason
 * @create 2017-12-30 0:51
 **/
public class PerformTestStudent {

    public static void main(String[] args) throws IOException {
        Student st = new Student("Tom", 'M', 20, 3.6);
        int loop = 1000000;
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < loop; i++) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream os = new ObjectOutputStream(bos);
            os.writeObject(st);
            os.flush();
            os.close();
            byte[] b = bos.toByteArray();
            bos.close();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("The jdk serialization cost time is : " + (endTime - startTime) + "ms");
        System.out.println("=======================================================================");

        ByteBuffer buffer = ByteBuffer.allocate(1024);
        startTime = System.currentTimeMillis();
        for (int i = 0; i < loop; i++) {
            byte[] bytes = st.codeC();
        }
        endTime = System.currentTimeMillis();
        System.out.println("The byte array serializable cost time is : " + (endTime - startTime) + "ms");
    }
}
